<?php
namespace Admin\Controller;

use Common\Common\CommonController;

/**
 * 收藏表
 * @author yjh
 *
 */
class CollectionController extends CommonController
{   
    private $Model;
    function __construct()
    {
        parent::__construct();
        
        $this->Model = M("member_collection");
    }
    
    public function index(){
        if (!IS_AJAX) {
            $this->display();
        }
        
        $offset = I('get.offset', 0);
        $limit = I('get.limit');
        $where="";
        if($_GET['mid']){
            $where = "member_collection.mid=".$_GET['mid'];
        }
        
        $data = array('total' => 0, 'rows' => array());
        $data['total'] = $this->Model->where($where)->limit($offset,$limit)->order("id asc")->count();
        if($data['total'] > 0){
            $data['rows'] = $this->Model->where($where)->limit($offset,$limit)->order("id asc")->select();
        }
         
        $this->ajaxReturn($data);
    }
    
    /**
     * 编辑
     */
    public function edit($id = 0){
    if(IS_POST){
            $data = I("post.");
            $this->Model->save($data);
            $this->success("编辑成功");
        }
        
        $data = $this->Model->find($id);
        if(empty($data)){
            $this->error('数据不存在或已被删除！');
        }
        
        $this->assign(array(
            'data' => $data
        ));
        $this->display();
    }
    
    public function delete($id = 0){
        if (empty($id)) {
            $this->error('删除项不能为空！');
        }
        $result = $this->Model->delete($id);
        if ($result) {
            $this->success('删除成功！');
        }
        $this->error('删除失败！');
        
    }
   
    
    
   
    
    
    
    
    
    
    
    
    
    
}
?>
